<!-- 我的路线 -->

<template>
  <div class="PatrolPlan-MyLine TaskTemplate-TemplateProcess marginBottom">
    <div class="flexCC alignCenter">
      <div class="flex3"><b>排序</b></div>
      <div class="flex7"><b>用户姓名</b></div>
      <div class="flex6"><b>联系方式</b></div>
      <div class="flex10"><b>岗位</b></div>
      <div class="flex20"><b>部门</b></div>
      <div class="flex4"><b>操作</b></div>
    </div>

    <div v-if="CORE.isEmpty(info.list)" class="TaskTemplate-TemplateProcess-list">
      <div class="flexCC alignCenter">
        <FormSlot noLabel flex3 disabled />
        <FormSlot noLabel flex7 disabled />
        <FormSlot noLabel flex6 disabled />
        <FormSlot noLabel flex10 disabled />
        <FormSlot noLabel flex20 disabled />
        <FormSlot noLabel flex4 disabled />
      </div>
    </div>

    <draggable v-model="info.list" :animation="200" class="TaskTemplate-TemplateProcess-list">
      <div v-for="(item, i) in info.list" :key="item.id" class="flexCC alignCenter">
        <FormSlot noLabel flex3>{{ i + 1 }}</FormSlot>
        <FormSlot noLabel flex7>{{ item.name }}</FormSlot>
        <FormSlot noLabel flex6>{{ CORE.maskPhone(item.phone) }}</FormSlot>
        <FormSlot noLabel flex10>{{ transJob(item) }}</FormSlot>
        <FormSlot noLabel flex20>{{ transOrgan(item) }}</FormSlot>
        <div class="flex4">
          <BtnText title="置顶" @click="toTop(i)" />
          <BtnText title="置底" @click="toBottom(i)" />
        </div>
      </div>
    </draggable>
  </div>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'SortList',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixScreen('sort')],

  /**
   * 本地方法 (轻量重要在前)
   */
  methods: {
    /**
     * 转换岗位
     */
    transJob(item) {
      const idList = item.jobTypeId ? item.jobTypeId.split(',') : []
      const nameList = item.jobTypeValue ? item.jobTypeValue.split(',') : []
      const jobList = idList.map((id, i) => CORE.dict(CORE.DICT.job_desc, id) || nameList[i] || '-')
      return jobList.join(', ')
    },

    /**
     * 转换组织
     */
    transOrgan(item) {
      const organList = item.organId.map((id) => (CORE.ORGAN.MAP[id] || {}).name || '-')
      return organList.join(', ')
    },

    /**
     * 置顶
     */
    toTop(i) {
      const items = this.info.list.splice(i, 1)
      this.info.list.unshift(items[0])
    },

    /**
     * 置底
     */
    toBottom(i) {
      const items = this.info.list.splice(i, 1)
      this.info.list.push(items[0])
    },
  },
}
</script>

<style lang="scss">
@import '@admin/views/Maintain/Task/TaskTemplate/MyModal/TemplateProcess/index.scss';
@import '@admin/views/Secure/Patrol/PatrolPlan/MyModal/MyLine/index.scss';
</style>
